-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OmegaConf.missing_keys to get a set of missing keys #719
Conversation
Closes #720 |
As I said, this is on hold until we start working on 2.2. In the mean time:
|
This pull request introduces 1 alert when merging 49b9d46 into 6c732c1 - view on LGTM.com new alerts:
|
From the doctest output:
The elements of a set are not guaranteed to be printed in any particular order... >>> sorted(OmegaConf.missing_keys({
... "foo": {"bar": "???"},
... "missing": "???",
... "list": ["a", None, "???"]
... }))
['foo.bar', 'list.2', 'missing'] |
Yeah it does sacrifice readability, I wonder if there is a way around it to make it verify the output rather than the output's representation. |
assert ret == {'list.2', 'foo.bar', 'missing'} |
omegaconf/omegaconf.py
Outdated
if not isinstance(cfg, Container): | ||
try: | ||
cfg = OmegaConf.create(cfg) | ||
except ValidationError: | ||
raise ValueError(f"Could not create a config out of {cfg}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it would be appropriate to use the _ensure_container
function here.
if not isinstance(cfg, Container): | |
try: | |
cfg = OmegaConf.create(cfg) | |
except ValidationError: | |
raise ValueError(f"Could not create a config out of {cfg}") | |
cfg = _ensure_container(cfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. once you do, you can also change your tests to take plain dict/list instead of a Container to simplfy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@omry The tests contain inputs of all types: ListConfig, DictConfig, plain list, dict. I think it doesn't hurt having it so, but if you think it's better with only plain lists/dicts I'll change it 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's test everything with plain dict and list, but keep a single test for DictConfig and a single test for ListConfig (just for the top level element).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 I've simplified it adding two tests at the end one with DictConfig and one with ListConfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please a news fragment file. This is similar to how it's done for Hydra.
Context here.
omegaconf/omegaconf.py
Outdated
if not isinstance(cfg, Container): | ||
try: | ||
cfg = OmegaConf.create(cfg) | ||
except ValidationError: | ||
raise ValueError(f"Could not create a config out of {cfg}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. once you do, you can also change your tests to take plain dict/list instead of a Container to simplfy.
I've added |
Co-authored-by: Omry Yadan <omry@fb.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few docs updates:
Co-authored-by: Jasha10 <8935917+Jasha10@users.noreply.github.com>
Co-authored-by: Jasha10 <8935917+Jasha10@users.noreply.github.com>
…megaconf into feature-request/missing_keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks @Ohad31415.
I think we can now revisit this PR since work on OmegaConf 2.2 has started. |
Made a merge commit to resolve conflicts with |
Merged. |
No description provided.